import './assets/main.css'
import router from "./router"
import { createApp } from 'vue'
import App from './App.vue'
import { createPinia } from 'pinia'
import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/reset.css';

import axios from 'axios';
// 创建 axios 实例，并设置默认配置
const axiosInstance = axios.create({
    baseURL: 'http://localhost:3000',  // 设置全局请求地址
    timeout: 10000,  // 设置超时
});
axiosInstance.interceptors.request.use(
    (config) => {
        // 在请求发送之前，可以添加 token 或做其他处理
        const token = localStorage.getItem('token');
        if (token) {
            config.headers['Authorization'] = `Bearer ${token}`;
        }
        return config;
    },
    (error) => {
        return Promise.reject(error);
    }
);

axiosInstance.interceptors.response.use(
    (response) => {
        return response;
    },
    (error) => {
        // 处理请求失败的情况
        console.error('Request failed:', error);
        return Promise.reject(error);
    }
);

const app = createApp(App);
app.use(Antd)
app.use(router)
app.use(createPinia())
app.config.globalProperties.$axios = axiosInstance;
app.mount('#app')